//
//  GAKKIFeatureCollectionViewConfiguration.m
//  GANGAIKit
//
//  Created by fh on 2019/11/8.
//  Copyright © 2019 cashchina. All rights reserved.
//

#import "GAKKIFeatureCollectionViewConfiguration.h"

@interface GAKKIFeatureCollectionViewConfiguration ()
/// 当使用默认系统布局的时候是否使用默认的item高度,默认跟宽度一样
@property (nonatomic, readwrite, assign) BOOL shouldUseDefaultLayoutItemHeight;
/// 当使用默认系统布局的时候是否使用默认的item宽度,默认跟高度一样
@property (nonatomic, readwrite, assign) BOOL shouldUseDefaultLayoutItemWidth;
/// 内部默认使用布局:外部没有设置布局属性的时候使用
@property (nonatomic, readwrite, strong) UICollectionViewFlowLayout *systemDefaultLayout;
@end

@implementation GAKKIFeatureCollectionViewConfiguration
#pragma mark - Life
- (instancetype)init {
    if (self = [super init]) {
        _collectionViewLayout = self.systemDefaultLayout;
        
        _shouldUseDefaultLayoutItemHeight = YES;
        _shouldUseDefaultLayoutItemWidth = YES;
        
        _sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _scrollDirection = UICollectionViewScrollDirectionVertical;
        _defaultLayoutEachColumnOrLineCountPriority = FlowLayoutDefaultLayoutEachColumnOrLineCountPriorityHigh;
        
        _defaultLayoutColumnCount = 1;
        _defaultLayoutColumnSpace = 10;
        _defaultLayoutItemWidth = 20;
        
        _defaultLayoutLineCount = 1;
        _defaultLayoutLineSpace = 10;
        _defaultLayoutItemHeight = 20;
        
        _itemSizeWHScale = 1;
        _shouldFitItemSizeWHScale = NO;
    }
    return self;
}

#pragma mark - Public
+ (instancetype)configuration {
    GAKKIFeatureCollectionViewConfiguration *configuration = [[GAKKIFeatureCollectionViewConfiguration alloc] init];
    return configuration;
}

#pragma mark - Setter and getter
- (void)setDefaultLayoutItemHeight:(CGFloat)defaultLayoutItemHeight {
    _defaultLayoutItemHeight = defaultLayoutItemHeight;
    _shouldUseDefaultLayoutItemHeight = NO;
}
- (void)setDefaultLayoutItemWidth:(CGFloat)defaultLayoutItemWidth {
    _defaultLayoutItemWidth = defaultLayoutItemWidth;
    _shouldUseDefaultLayoutItemWidth = NO;
}
- (void)setItemSizeWHScale:(CGFloat)itemSizeWHScale {
    _itemSizeWHScale = itemSizeWHScale;
    _shouldUseDefaultLayoutItemWidth = NO;
    _shouldUseDefaultLayoutItemHeight = NO;
}

- (void)setScrollDirection:(UICollectionViewScrollDirection)scrollDirection {
    _scrollDirection = scrollDirection;
    _systemDefaultLayout.scrollDirection = scrollDirection;
}
- (UICollectionViewFlowLayout *)systemDefaultLayout {
    if (!_systemDefaultLayout) {
        _systemDefaultLayout = [UICollectionViewFlowLayout new];
        _systemDefaultLayout.scrollDirection = self.scrollDirection;
    }
    return _systemDefaultLayout;
}
@end
